package cn.wyj.basic.controller;

import cn.wyj.basic.deo.PhoneSmsCodeDto;
import cn.wyj.basic.service.IVerifyCodeService;
import cn.wyj.basic.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/verifyCode")
public class VerifyCodeController {

    @Autowired
    private IVerifyCodeService verifyCodeService;

    /**
     * 获取图形验证码
     */
    @GetMapping("/image/{key}")
    public AjaxResult getImageCode(@PathVariable("key") String uuidKey){
        String base64Code = verifyCodeService.getImageCode(uuidKey);
        return AjaxResult.me().success(base64Code);
    }

    /**
     * 获取短信验证码
     */
    @PostMapping("/smsCode")
    public AjaxResult smsCode(@RequestBody @Valid PhoneSmsCodeDto dto){
        verifyCodeService.smsCode(dto);
        return AjaxResult.me().success();
    }
}
